<!--DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<style type="text/css">
#div{
	display: block;
}
div{
	display: none;
}
.curr{
	display: block;
	color: red;
}
#ul{
	width: 500px;
	height: 400px;
}
li{
	font-size: 70px;
}


</style>
<body>
	<ul id="ul">
		<li>经济</li>
		<li>科技</li>
		<li class="curr">军事</li>
	</ul>
	<div id="div">
		<div>经济新闻列表</div>
		<div>科技新闻列表</div>
		<div class="curr">军事新闻列表</div> 
	</div>

<script type="text/javascript">
function $(s){
	return document.querySelectorAll(s);
}
var li = $("li"),divs = $("div")
console.log(li[1].innerText)
 
for (var i = 0; i < li.length; i++) {
li[i].onclick = function(e){
	for (var k = 0; k < li.length; k++) {
	if(this.className=="curr"){
		divs[k+1].className = "curr";
	}
}
}
}

console.log(li)



</script>
</body>
</html-->

<!--DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<input type="text" name="" id="studentName">
	<button id="addBtn">增加</button>
	<div id="student">
		<ul id="studentList"></ul>
	</div>

<script type="text/javascript">
function $(s){
	return document.querySelectorAll(s);
}
var studentName = $("#studentName")[0],
	addBtn=$("#addBtn")[0],
	studentList=$("#studentList")[0]

	function inArray(arr,item){
		for (var i = 0; i < arr.length; i++) {
			
		}
	}
	var reg = /\w/g;
	//test正则表达式
	addBtn.onclick = function(){
		var sname = studentName.value;
		if (sname.length>2&&!inArray(studentArr,aname)&&!reg.test(sname)) {
			studentArr.push(sname);
			//1.遍历数组
			//2.添加数组元素，在页面追加dom节点
			var li = document.createElement("li");
			li.innerHTML = sname;
			studentList.inserBefore(li,studentList.firstChild);
			
		}
	}

(function(){
	var a=b=1;
})();
console.log(b)
console.log(a)
</script>
</body>
</html-->

<!--DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>

<script type="text/javascript">
for (var i = 0,j=0; i<5,j<9; i++,j++) {
	console.log(i);
}
function f(){
	console.log(this);
}
var arr = ["a","b"];
arr.a=f;
arr.a();

setTimeout(arr.a,1000);
var a = (1,2,3);
console.log(a);
//点击按钮随机生成数组
</script>
</body>
</html-->

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<style type="text/css">
p{height: 100px;}

</style>
<body>
	<ul id="ul">
		<li>
			<button id="btn">删除</button>
		</li>
		<li>
			<button>删除</button>
		</li>
		<li>
			<button>删除</button>
		</li>
	</ul>


	<input type="" id="input" value=" makdf akl">
	<button id="abc">添加</button>
		<p></p>
<div id="div" data-address="北京市"></div>
<script type="text/javascript">


/*
var an = document.getElementById("abc");
var input = document.getElementById("input");
var p = document.getElementsByTagName("p")[0];
console.log(p);

an.addEventListener("click",function(e){
	p.innerText = input.value;
})

var arr = "5,6,3,2,1,4";
var b = arr.match(5);
console.log(b)
*/

console.log(document.getElementById("div").dataset.address)
var ul = document.getElementById("ul"),

li =document.getElementsByTagName("li"),
p = document.createElement("p"),
btn = ul.getElementsByTagName("button")

ul.onclick=function(e){
 if (e.target.tagName=="BUTTON"&&e.target.innerText=="删除") {
 	var index=getIndex(btn,e.target);
 	ul.removeChild(li[index]);
 }
}
function getIndex(ele,item){
	for (var i = 0; i < ele.length; i++) {
		if (ele[i]==item) {//点击的按钮=目标
			return i;
		}
	}
	return -1;
}

//toFixed(几个小数)取小数
//substring()
var num =99;
var pai = Math.PI;//3.142
console.log(pai.substring(0,));

</script>
</body>
</html>